﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Transactions;

namespace LetLord.Models
{
    public enum NumberOfBedrooms { One = 1, Two = 2, Three = 3, Four = 4, Five = 5, 
                                   Six = 6, Seven = 7, Eight = 8, Nine = 9, Ten = 10 }

    [Table("Tenant")]
    public class Tenant : UserProfile
    {
        public Tenant()
        {
            this.ReferencePhotos = new List<ReferencePhoto>();
            this.TenantGroupMembers = new List<TenantGroupMember>();
            this.Viewings = new List<Viewing>();
            this.SavedProperties = new List<SavedProperty>();
        }

        //[Required(ErrorMessage="Age is required")]
        [StringLength(3, MinimumLength=2, ErrorMessage="Age must be between 16 and 110")]
        [Display(Name="Age")]
        public string TenantAge { get; set; }

        //[Required(ErrorMessage = "Please enter a short description about yourself")]
        [DataType(DataType.MultilineText)]
        [StringLength(500, MinimumLength = 1, ErrorMessage = "You must write something about yourself")]
        [Display(Name = "About me")]
        public string PersonalDescription { get; set; }

        //[Required(ErrorMessage = "Please specify your minumum budget")]
        [Display(Name = "Minimum rate:")]
        public decimal MinBudget { get; set; }

        //[Required(ErrorMessage = "Please specify your maximum budget")]
        [Display(Name = "Maximum rate: ")]
        public decimal MaxBudget { get; set; }

        //[Required(ErrorMessage = "Please specify if you work full time")]
        [Display(Name = "Full-time employee: ")]
        public bool IsProfessional { get; set; }

        //[Required(ErrorMessage = "Please specify if you are a student")]
        [Display(Name = "Full-time student: ")]
        public bool IsStudent { get; set; }

        //[Required(ErrorMessage = "Please specify if you plan to live with children")]
        [Display(Name = "Live with children: ")]
        public bool HasChildren { get; set; }

        //[Required(ErrorMessage = "Please specify if you have rent allowance")]
        [Display(Name = "Receive rent allowance: ")]
        public bool HasRentAllowance { get; set; }

        //[Required(ErrorMessage = "Please specify if you are acting on behalf of a group of tenants")]
        [Display(Name = "Represent group of tenants: ")]
        public bool IsInGroup { get; set; }

        [Display(Name = "Have pets: ")]
        public bool HasPets { get; set; }

        [NotMapped]
        public bool HasReferences { get; set; }

        //[Required(ErrorMessage = "Please specify when you want to rent from")]
        //[Display(Name = "Rent from")]
        //[DataType(DataType.DateTime)]
        //[DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:dd/mm/yyyy}")]
        //public DateTime DateWantToRentFrom { get; set; }

        //[Required(ErrorMessage = "Please specify when you want to rent to")]
        //[Display(Name = "Rent to")]
        //DataType(DataType.DateTime)]
        //[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/mm/yyyy}")]
        //public DateTime DateWantToRentTo { get; set; }

        //[Required(ErrorMessage = "Please specify where you want to rent")]
        [Display(Name = "Desired location")]
        public string DesiredPropertyLocation { get; set; }

        [Display(Name = "Desired property type")]
        public PropertyType DesiredPropertyType { get; set; }

        //[Required(ErrorMessage = "Please specify how many bedrooms you want")]
        [Display(Name = "Number of bedrooms: ")]
        public NumberOfBedrooms DesiredNumberOfBedrooms { get; set; }            

        public virtual string DesiredNumberOfBedroomsString
        {
            get { return DesiredNumberOfBedrooms.ToString(); }
            set
            {
                NumberOfBedrooms newValue;
                if (Enum.TryParse(value, out newValue))
                { DesiredNumberOfBedrooms = newValue; }
            }
        }

        [Display(Name="Desired Property Type: ")]
        public virtual string DesiredPropertyTypeString
        {
            get { return DesiredPropertyType.ToString(); }
            set
            {
                PropertyType newValue;
                if (Enum.TryParse(value, out newValue))
                { DesiredPropertyType = newValue; }
            }
        }

        // A Tenant can have many ReferencePhotos
        //[ForeignKey("ImageId")]
        public virtual ICollection<ReferencePhoto> ReferencePhotos { get; set; }

        // A Tenant can have many TenantGroupMembers
        //[ForeignKey("TenantGroupMemberId")]
        public virtual ICollection<TenantGroupMember> TenantGroupMembers { get; set; }

        // A Tenant can go to many Viewings
        //[ForeignKey("ViewingId")]
        public virtual ICollection<Viewing> Viewings { get; set; }

        // A Tenant can have many SavedProperties
        //[ForeignKey("ResidentialPropertyId")]
        public virtual ICollection<SavedProperty> SavedProperties { get; set; }
    }
}